<template>
  <div id="home">
    <home-header/>
    <swiper :swiperList="swiperList"/>
    <icons :iconList="iconList"/>
    <recommend :recommendList="recommendList"/>
    <weekend :weekendList="weekendList"/>
  </div>
</template>
<script>
  import HomeHeader from './components/Header'
  import Swiper from './components/Swiper'
  import Icons from './components/Icons'
  import Recommend from './components/Recommend'
  import Weekend from './components/Weekend'
  import axios from 'axios'
  import {mapState} from 'vuex'
  export default {
    name: 'Home',
    components: {
      HomeHeader,
      Swiper,
      Icons,
      Recommend,
      Weekend
    },
    data() {
      return {
        lastCity: '',
        swiperList: [],
        iconList: [],
        recommendList: [],
        weekendList: []
      }
    },
    mounted() {
      this.lastCity = this.city
      this.getHomeInfo()
    },
    computed: {
      ...mapState(['city'])
    },
    methods: {
      getHomeInfo() {
        axios.get('/api/index.json?city=' + this.city)
          .then(this.getHomeInfoSucc)
      },
      getHomeInfoSucc(res) {
        /*console.log(res);*/
        res = res.data
        if (res.ret && res.data) {
          const data = res.data
          this.swiperList = data.swiperList
          this.iconList = data.iconList
          this.recommendList = data.recommendList
          this.weekendList = data.weekendList
        }
      }
    },
    activated() {
      if(this.lastCity !== this.city) {
        this.lastCity = this.city
        this.getHomeInfo()
      }
    }
  }
</script>

<style scoped>

</style>
